package com.bw.sofa_module.sofa;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.bw.sofa_module.R;
import com.bw.sofa_module.contentsofa.ContentFragment;
import com.bw.sofa_module.picturesofa.PictureFragment;
import com.bw.sofa_module.videosofa.VideosFragment;
import com.bw.widget_sdk.FragmentAdapter;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

public class SofaFragment extends Fragment {
    private ViewPager sofaViewPager;
    private View view;
    private ArrayList<Fragment> fragment_list = new ArrayList<>();
    private SlidingTabLayout sofaTab;
    private List<String> titles = new ArrayList<>();
    private RecyclerView.RecycledViewPool recycledViewPool;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        recycledViewPool = new RecyclerView.RecycledViewPool();
        recycledViewPool.setMaxRecycledViews(0,10);
        fragment_list.add(new PictureFragment(recycledViewPool));
        fragment_list.add(new VideosFragment());
        fragment_list.add(new ContentFragment());
        titles.add("图片");
        titles.add("视频");
        titles.add("文本");
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_sofa, container, false);
        sofaViewPager = view.findViewById(R.id.sofa_viewPager);
        sofaTab = view.findViewById(R.id.sofa_tab);
        sofaViewPager.setAdapter(new FragmentAdapter(getChildFragmentManager(), fragment_list, titles));
        sofaTab.setViewPager(sofaViewPager);
        return view;
    }
}
